package com.example.blog.entity;

import lombok.Data;
import java.util.Date;
import java.util.List;

@Data
public class Article {

    private Long id;
    private String title;
    private String content;
    private String coverImage;
    private Integer viewCount;
    private Integer likeCount;
    private Date createTime;
    private Date updateTime;
    private Long userId;
    private List<Long> categoryIds;
    // 非数据库字段，用于展示
    private User user;
    private Category category;

    // 可以添加一个方法来初始化默认值
    public void init() {
        if (createTime == null) {
            createTime = new Date();
        }
        updateTime = new Date();
        if (viewCount == null) {
            viewCount = 0;
        }
        if (likeCount == null) {
            likeCount = 0;
        }
    }

}